package com.hengpeng.itfints.service.bankproduct.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

import com.hengpeng.common.exception.ServiceResult;
import com.hengpeng.common.persist.QueryResult;
import com.hengpeng.common.persist.query.DynamicQuery;
import com.hengpeng.common.persist.query.constants.QueryConstants.QueryType;
import com.hengpeng.itfinbase.persist.BankProduct;
import com.hengpeng.itfinbase.persist.BankProduct.ProductType;
import com.hengpeng.itfints.service.ServiceFactory;
import com.hengpeng.itfints.service.bankproduct.BankProductService;

@Lazy
@Service
public class BankProductServiceImpl implements BankProductService
{
	@Autowired
	private ServiceFactory serviceFactory;

	@Override
	public ServiceResult<List<BankProduct>> queryList(Integer pageIndex, Integer pageSize,ProductType productType)
	{
		DynamicQuery query = new DynamicQuery(BankProduct.class);
		if (productType != null) {
			query.eq("productType", productType);
		}
		query.desc("createTime");
		query.setPageIndex(pageIndex);
		query.setPageSize(pageSize);
		query.setQueryType(QueryType.JDBC);
		query.setIsSearchTotalCount(true);
		QueryResult<BankProduct> requery = serviceFactory.getPersistService().findWithPage(BankProduct.class, query);
		Long count = requery.getTotalCount();
		ServiceResult<List<BankProduct>> serviceResult = new ServiceResult<List<BankProduct>>();// 设置返回值
		serviceResult.setReturnValue(requery.getResults());
		serviceResult.setReturnListSize(count.intValue());
		return serviceResult;
	}
	@Override
	public List<BankProduct> findBankProductListByType(ProductType productType, Integer count)
	{
		DynamicQuery query = new DynamicQuery(BankProduct.class, "a");
		query.eq("a.productType", productType);
		query.setPageSize(count);
		query.desc("a.createTime");
		QueryResult<BankProduct> requery = serviceFactory.getPersistService().findWithPage(BankProduct.class, query);
		return requery.getResults();
	}
}
